<template>
	<view>
		<view class="contbut">
			<view class="" v-for="(item,index) in list" :key="item.id" @tap="clickthree(item.nickna)">
				<image class="butimg" :src="item.img" mode=""></image>
				<view class="">
					{{item.title}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import $http from '@/common/api/request.js'
	import {
		mapMutations
	} from 'vuex'
	export default {
		name: "login",
		data() {
			return {
				list: [{
						id: 0,
						title: "微信登录",
						nickna: "weixin",
						img: "/static/tabBar/weixin.jpg"
					},
					{
						id: 1,
						title: "微博登录",
						nickna: "sinaweibo",
						img: "/static/tabBar/weibo.jpg"
					},
					{
						id: 2,
						title: "qq登录",
						nickna: "qq",
						img: "/static/tabBar/qq.jpg"
					},
				],
				thecop: -1
			};
		},
		methods: {
			...mapMutations(['login']),
			clickthree(m) {
				// uni.showToast({
				// 	title:"测试v3,无法使用!请使用手机号注册",
				// 	duration:1500,
				// 	icon:"none"
				// })
				uni.login({
					provider: m,
					success: (res) => {
						//直接获取账号的信息:包含姓名,头像....
						uni.getUserInfo({
							provider: m,
							success: (res) => {

								let provider = m;
								let openid = res.userInfo.openId || res.userInfo.openid;
								let nickName = res.userInfo.nickName;
								let avatarUrl = res.userInfo.avatarUrl;
								$http.request({
									url: "/loginother",
									method: "POST",
									data: {
										provider,
										openid,
										nickName,
										avatarUrl
									}
								}).then((res) => {
									this.login(res);
									uni.redirectTo({
										url: "/pages/index/index"
									})

								}).catch(() => {

								})




							}
						})
					}
				})
			}
		}

	}
</script>

<style lang="scss">
	.contbut {
		display: flex;
		justify-content: space-around;
		align-items: center;
		padding: 0 10rpx;

		.butimg {
			width: 120rpx;
			height: 120rpx;
		}
	}
</style>